package com.cqtczh.qhd.driver.acticity;

import android.annotation.SuppressLint;
import android.app.ActivityGroup;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

import com.google.gson.Gson;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.RequestParams;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest;
import com.cqtczh.qhd.driver.R;

public class CMainActivity extends ActivityGroup implements OnClickListener {


	private HttpUtils http;
	private RequestParams params;
	private Gson gson;
	private Button b1,b2,b3,b4;

	@SuppressLint("NewApi")
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.cmain_activity);
		b1 = (Button) findViewById(R.id.createTrace);
		b1.setOnClickListener(this);
		b2 = (Button) findViewById(R.id.createSeverice);
		b2.setOnClickListener(this);
		//GetLbsUtil.getlbs();
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.createTrace:
			createTrace();
			break;
		case R.id.createSeverice:
			createSeverice();
		default:
			break;
		}
		
	}

	private void createSeverice() {
		http = new HttpUtils();
		params = new RequestParams();
		params.addBodyParameter("name", "神车");
		params.addBodyParameter("ak", "gB366cpuqM03bQ9uMAnBSGjr");
		params.addBodyParameter("desc", "神车是我的预留车辆");
		http.send(HttpRequest.HttpMethod.POST, "http://api.map.baidu.com/trace/v1/service/create", params,
				new RequestCallBack<String>() {


					@Override
					public void onSuccess(ResponseInfo<String> responseInfo) {

						System.out.println("进入更新过程。。。。");
						Gson gson2 = new Gson();
						System.out.println(responseInfo.result);
					}

					@Override
					public void onFailure(HttpException error, String msg) {

						System.out.println("进来就失败了");
					}
				});
	}

	private void createTrace() {
		http = new HttpUtils();
		params = new RequestParams();
		params.addBodyParameter("service_id", "83819");
		params.addBodyParameter("ak", "gB366cpuqM03bQ9uMAnBSGjr");
		params.addBodyParameter("latitude", "29.588357");
		params.addBodyParameter("longitude", "107.53159");
		params.addBodyParameter("coord_type", 1 + "");//1：GPS经纬度坐标2：国测局加密经纬度坐标 3：百度加密经纬度坐标。必选
		params.addBodyParameter("loc_time", System.currentTimeMillis()/1000 +"");
		params.addBodyParameter("track_name", "渝A12345");
		params.addBodyParameter("title", "同城智慧小车");
		params.addBodyParameter("tags", "E货滴");
		http.send(HttpRequest.HttpMethod.POST, "http://api.map.baidu.com/trace/v1/track/create", params,
				new RequestCallBack<String>() {


					@Override
					public void onSuccess(ResponseInfo<String> responseInfo) {

						System.out.println("进入更新过程。。。。");
						Gson gson2 = new Gson();
						System.out.println(responseInfo.result);
					/*	if (state.getCode().equals(State.SUCEECCODE)) {

							finish();
						} else
							System.out.println("人生的失败");*/
					}

					@Override
					public void onFailure(HttpException error, String msg) {

						System.out.println("进来就失败了");
					}
				});	
	}

	
}
